//
// Created by Administrator on 2023/11/21.
//
#include "iostream"
#include "algorithm"

using namespace std;

const int N = 1e5 + 15;

int a[N];

int main() {
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    sort(a, a + n);

    int res=0,sum=0;
    for (int i = 1; i < n; ++i) {
        res=a[i-1]+res;//第i个任务需要等待的时间
        sum+=res;
    }
    cout<<sum;
}